//https://leetcode.cn/problems/longest-turbulent-subarray/

class Solution {
public:
    int maxTurbulenceSize(vector<int>& nums) {
        int n = nums.size();

        vector<int> f(n, 1), g(n, 1);
        int ret = 1;

        for (int i = 1; i < n; i++)
        {
            if (nums[i - 1] > nums[i]) g[i] = f[i - 1] + 1;
            if (nums[i - 1] < nums[i]) f[i] = g[i - 1] + 1;
            ret = max(ret, max(f[i], g[i]));
        }

        return ret;

    }
};